//
//  HCMineAnswerView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/18.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineAnswerView.h"

#import "HCMineAnswerTableViewCell.h"

#import "HCMineAnswerdModel.h"

@interface HCMineAnswerView () <UITableViewDelegate,UITableViewDataSource> {
    UITableView *tableView_;
    HCMineAnswerdModel *model_;
}

@end

@implementation HCMineAnswerView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubViews:frame];
    }
    return self;
}

-(void)initializeSubViews:(CGRect)frame {
    tableView_ = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, frame.size.width-20, frame.size.height)];
    tableView_.backgroundColor = YBKRGBCOLOR(242, 242, 242, 1);
    tableView_.delegate = self;
    tableView_.dataSource = self;
    tableView_.showsVerticalScrollIndicator = NO;
    tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_.rowHeight = 250;
    [self addSubview:tableView_];
    
    [tableView_ registerNib:[UINib nibWithNibName:@"HCMineAnswerTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"mineanswercell"];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return model_.myanswer.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCMineAnswerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mineanswercell" forIndexPath:indexPath];
    if (model_) {
        HCMineAnswerdData *data = model_.myanswer[indexPath.row];
        cell.model = data;
    }
    return cell;
}

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

-(void)setModel:(id)model {
    model_ = (HCMineAnswerdModel *)model;
    [tableView_ reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
